<%@ page import="java.util.Date" %><%--
  Created by IntelliJ IDEA.
  User: 李雨昂
  Date: 2019/9/16
  Time: 14:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <meta charset="utf-8">
</head>
<body>
<%= new Date()%>

<div id="outer"></div>

<button type="button" onclick="add()">发送get请求</button>


<script>

    function add(){
        //1.创建一个XMLHttpRequest对象
        var request = new XMLHttpRequest();

        //2.注册回调函数
//            readyState5个状态值
//            只要这个值发生了变化,那么就会触发这个回调函数
        request.onreadystatechange = function(){
            //回调函数中可以获取到后台返回的数据
            if (request.readyState == 4){
                if (request.readyState ==200){
                    var result = request.responseText;
                    //js操作dom
                    document.getElementById("outer").innerText = result;
                }
            }
        }
        //3. 准备请求的参数
        request.open("GET","/jsp/hello/ajax?name = tom");
        //4. 发送请求
        request.send();
    }
</script>
</body>
</html>
